Refactor DFT+U: rename and de-static Plus_U members, step 3 - #7859
Merged
Conversation
- Rename U -> u_current, U0 -> u_target, omc -> occ_mat_ctrl, Yukawa -> use_yukawa - Rename accessors: get_hubbard_u -> get_u_current, get_hubbard_u0 -> get_u_target - Remove static qualifier from all 9 Plus_U_Base members (u_current, u_target, occ_mat_ctrl, use_yukawa, energy_u, orbital_corr, uramping, mixing_dftu, nspin) - Convert static accessors (get_energy, set_energy, get_u_current, etc.) and is_mixing_enabled/enable_mixing to non-static member functions - Extend Plus_U_Base::init_base() and Plus_U::init() signatures to accept hubbard_u, uramping, occ_mat_ctrl, mixing_dftu; move initialization logic out of input_conv.cpp into init_base() so members are set after the Plus_U instance is constructed (no longer relies on static state) - Remove redundant Plus_U assignments from input_conv.cpp; drop its include of dftu.h (dependencies made explicit at call sites) - Introduce ElecState::set_dftu_energy() / dftu_energy_ member so get_dftu_energy() no longer depends on Plus_U::get_energy() static state; ESolver_KS_PW and ESolver_KS_LAO push the energy after DFT+U update - Replace PARAM.inp.* with inp.* in setup_pot.cpp (inp is already a parameter) - Rename Input_para::omc -> occ_mat_ctrl (INPUT keyword 'omc' preserved for backward compatibility) Verification: pending (compilation and tests to be run by user)
added 9 commits
August 25, 2026 19:41
… force and stress
Seven members (yukawa_lambda, npol, nlocal, gamma_only_local, ks_solver, cal_force, cal_stress) were only read by the LCAO subclass (Plus_U) and its component files under source_lcao/module_dftu/. They are now declared in Plus_U and assigned in Plus_U::init, so Plus_U_Base no longer carries LCAO-specific mutable workflow state. Accordingly shorten Plus_U_Base::init_base signature by six parameters (yukawa_lambda, nlocal, gamma_only_local, ks_solver, cal_force, cal_stress); update the two call sites (Plus_U::init in dftu.cpp, PW path in setup_pot.cpp). Plus_U::init keeps its original signature so external callers (lcao_set.cpp) are unaffected.
dftu.hpp only provided the empty primary template for hamilt::DFTU. Move it into dftu_lcao.h (the sole includer), guarded by __DFTUTEMPLATE, matching the convention used by sibling LCAO operators (nonlocal.h, ekinetic.h, meta_lcao.h, veff_lcao.h, etc.) that inline the primary template instead of using a separate .hpp file. This also aligns with AGENTS.md rule 4 (avoid .hpp implementation headers).
Three LCAO DFT+U files had confusing names that hid which was the main implementation, the new operator, and the legacy operator. Rename for clarity: - dftu.h/.cpp -> dftu_lcao.h/.cpp : Plus_U class (LCAO DFT+U physics, subclass of Plus_U_Base in dftu_base.h). The name now mirrors dftu_base.h. - dftu_lcao.h/.cpp -> dftu_lcao_op.h/.cpp : hamilt::DFTU operator (new method, dft_plus_u==1, onsite_radius projections). Operators now carry the _op suffix. - op_dftu_lcao.h/.cpp -> dftu_lcao_op_legacy.h/.cpp : hamilt::OperatorDFTU operator (old method, dft_plus_u==2, NAO first zeta projections, test-only). Renamed to mark it as legacy and group it with the new operator. Class names are unchanged in this step (Plus_U, hamilt::DFTU, hamilt::OperatorDFTU); only filenames and #include paths change. Updated all ~40 includers across source_lcao, source_pw, source_esolver, source_estate, source_io, plus the module and test CMakeLists (the dftu_lcao_test links the new-operator cpp ../dftu_lcao_op.cpp, not the Plus_U cpp).
…yers
Replace Plus_U (LCAO-derived class) with Plus_U_Base (PW-layer base class) in
all non-LCAO interfaces. All DFT+U calls in PW/estate/test layers only use
base-class members, so the derived-type reference was unnecessary.
Changes:
- Remove #include "source_lcao/module_dftu/dftu_lcao.h" from PW/base headers
- Use #include "source_pw/module_pwdft/dftu_base.h" instead
- Replace Plus_U&/Plus_U* with Plus_U_Base&/Plus_U_Base* in:
* source_pw/module_pwdft: force_pw, hamilt_pw, onsite_proj, op_pw_proj,
stress_func, stress_onsite, stress_pw (6 headers + 7 impls)
* source_estate/module_charge: chgmixing (PW + LCAO mixing functions)
* source_pw/module_stodft/test: test_hamilt_sto, test_sto_tool
* source_hsolver/test: diago_mock.h (3 explicit specializations)
Plus_U (derived) instances held by callers (e.g. ESolver_KS::dftu) continue
to work via implicit pointer/reference upcast to Plus_U_Base. No behavioral
change.
lanshuyue
approved these changes
Aug 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.